﻿
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
namespace INTEX.DataBase.Tools
{
    public partial class INTEXDBC
    {
        public void MapICC_PRULES(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveICC_PRULES(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet Result = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            Result = QueryICC_PRULES(dwData);
            if (Result.Tables.Count > 0)
            {
                tbLocal = Result.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }

            MapICC_PRULES(ref dwLocal, dwData);

            if (!flgExist)
            {
                dwLocal["ROWNID"] = GetSeq();
                InsertICC_PRULES(dwLocal, ITXDBVERSION);
            }
            UpdateICC_PRULES(dwLocal);
        }
        public void InsertICC_PRULES(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            string table = "VVPACK";  //VVPMANDANT	VVPLIEFSCH	VVPPACKNR
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "50.24":
                    or1.CommandText = "INSERT INTO ICC_PRULES(ROWNID, PLANID,RGROUP, RULEID, ARTSTAGE,R01)"
                                + " VALUES (:ROWNID, :PLANID,:RGROUP, :RULEID, :ARTSTAGE,:R01 )";
                     or1.Parameters.Add("ROWNID", OracleType.NVarChar).Value = dwData["ROWNID"].ToString();
                     or1.Parameters.Add("PLANID", OracleType.NVarChar).Value = dwData["PLANID"].ToString();
                     or1.Parameters.Add("RGROUP", OracleType.NVarChar).Value = dwData["RGROUP"].ToString();
                     or1.Parameters.Add("RULEID", OracleType.NVarChar).Value = dwData["RULEID"].ToString();
                     or1.Parameters.Add("ARTSTAGE", OracleType.NVarChar).Value = dwData["ARTSTAGE"].ToString(); 
                     or1.Parameters.Add("QTYENDDES", OracleType.NVarChar).Value = dwData["QTYENDDES"].ToString();
                     or1.Parameters.Add("R01", OracleType.NVarChar).Value = dwData["R01"].ToString(); 
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        }

        public DataSet QueryICC_PRULES(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "SELECT * FROM ICC_PRULES WHERE   ROWNID=:ROWNID"; ;
                    or1.Parameters.Add("ROWNID", OracleType.NVarChar).Value = dwData["ROWNID"].ToString();
                    break;
                case 9999:
                    or1.CommandText = "SELECT * FROM ICC_PRULES WHERE PLANID=ORDERNUM";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "ICC_PRULES";
            Return = Result;
            return Return;
        }
        public void UpdateICC_PRULES(DataRow dwData, int options = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (options)
            {
                case 1:
                    #region====Command====
                    or1.CommandText = "UPDATE ICC_PRULES SET  " 
                        +"PLANID=:PLANID,"
                        +"RGROUP=:RGROUP,"
                        +"RULEID=:RULEID,"
                        +"ARTSTAGE=:ARTSTAGE,"
                        +"ORDERNUM=:ORDERNUM,"
                        +"ART=:ART,"
                        +"COLOR=:COLOR,"
                        +"FINISH=:FINISH,"
                        +"AUFTYP=:AUFTYP,"
                        +"QTYEND=:QTYEND,"
                        +"QTYENDDES=:QTYENDDES,"
                        +"R01=:R01,"
                        +"R01DES=:R01DES,"
                        +"R02=:R02,"
                        +"R02DES=:R02DES,"
                        +"F01=:F01,"
                        +"F01DES=:F01DES,"
                        +"F02=:F02,"
                        +"F02DES=:F02DES,"
                        +"JNUM=:JNUM,"
                        +"JNUMDES=:JNUMDES,"
                        +"JWASTGE=:JWASTGE,"
                        +"JWASTAGEDES=:JWASTAGEDES,"
                        +"QTYMAT=:QTYMAT,"
                        +"REMARK=:REMARK "
                        + " WHERE  "
                        + "   ROWNID=:ROWNID ";
                    #endregion
                    #region====Parameters==== 
                     or1.Parameters.Add("ROWNID", OracleType.NVarChar).Value = dwData["ROWNID"].ToString();
                     or1.Parameters.Add("PLANID", OracleType.NVarChar).Value = dwData["PLANID"].ToString();
                     or1.Parameters.Add("RGROUP", OracleType.NVarChar).Value = dwData["RGROUP"].ToString();
                     or1.Parameters.Add("RULEID", OracleType.NVarChar).Value = dwData["RULEID"].ToString();
                     or1.Parameters.Add("ARTSTAGE", OracleType.NVarChar).Value = dwData["ARTSTAGE"].ToString();
                     or1.Parameters.Add("ORDERNUM", OracleType.NVarChar).Value = dwData["ORDERNUM"].ToString();
                     or1.Parameters.Add("ART", OracleType.NVarChar).Value = dwData["ART"].ToString();
                     or1.Parameters.Add("COLOR", OracleType.NVarChar).Value = dwData["COLOR"].ToString();
                     or1.Parameters.Add("FINISH", OracleType.NVarChar).Value = dwData["FINISH"].ToString();
                     or1.Parameters.Add("AUFTYP", OracleType.NVarChar).Value = dwData["AUFTYP"].ToString();
                     or1.Parameters.Add("QTYEND", OracleType.NVarChar).Value = dwData["QTYEND"].ToString();
                     or1.Parameters.Add("QTYENDDES", OracleType.NVarChar).Value = dwData["QTYENDDES"].ToString();
                     or1.Parameters.Add("R01", OracleType.NVarChar).Value = dwData["R01"].ToString();
                     or1.Parameters.Add("R01DES", OracleType.NVarChar).Value = dwData["R01DES"].ToString();
                     or1.Parameters.Add("R02", OracleType.NVarChar).Value = dwData["R02"].ToString();
                     or1.Parameters.Add("R02DES", OracleType.NVarChar).Value = dwData["R02DES"].ToString();
                     or1.Parameters.Add("F01", OracleType.NVarChar).Value = dwData["F01"].ToString();
                     or1.Parameters.Add("F01DES", OracleType.NVarChar).Value = dwData["F01DES"].ToString();
                     or1.Parameters.Add("F02", OracleType.NVarChar).Value = dwData["F02"].ToString();
                     or1.Parameters.Add("F02DES", OracleType.NVarChar).Value = dwData["F02DES"].ToString();
                     or1.Parameters.Add("JNUM", OracleType.NVarChar).Value = dwData["JNUM"].ToString();
                     or1.Parameters.Add("JNUMDES", OracleType.NVarChar).Value = dwData["JNUMDES"].ToString();
                     or1.Parameters.Add("JWASTGE", OracleType.NVarChar).Value = dwData["JWASTGE"].ToString();
                     or1.Parameters.Add("JWASTAGEDES", OracleType.NVarChar).Value = dwData["JWASTAGEDES"].ToString();
                     or1.Parameters.Add("QTYMAT", OracleType.NVarChar).Value = dwData["QTYMAT"].ToString();
                     or1.Parameters.Add("REMARK", OracleType.NVarChar).Value = dwData["REMARK"].ToString();
                    #endregion
                    break;
            }

            Connect2Proxy(or1);
        }
    }
}
